package com.anyisn.anyflickr.modules.PhotoInfo.view
{
	import com.anyisn.anyflickr.modules.PhotoInfo.PhotoInfoModuleFacade;
	import com.anyisn.anyflickr.shell.ShellFacade;
	import com.anyisn.puremvc.as3.multicore.utilities.pipes.component.PipeAwareModule;
	
	import org.puremvc.as3.multicore.interfaces.INotification;
	import org.puremvc.as3.multicore.utilities.pipes.interfaces.IPipeMessage;
	import org.puremvc.as3.multicore.utilities.pipes.messages.Message;
	import org.puremvc.as3.multicore.utilities.pipes.plumbing.Junction;
	import org.puremvc.as3.multicore.utilities.pipes.plumbing.JunctionMediator;
	
	public class ModuleJunctionMediator extends JunctionMediator
	{
		public static const NAME:String = 'PhotoInfoJunctionMediator';
		
		public function ModuleJunctionMediator()
		{
			super(NAME, new Junction());
		}
		
		override public function listNotificationInterests() : Array {
			var interests:Array = super.listNotificationInterests();
			interests.push(PhotoInfoModuleFacade.EXPORT_PHOTO_INFO_WINDOW);
//			interests.push(ShellFacade.PHOTO_DOWNLOAD);
//			interests.push(ShellFacade.FAVORITES_ADD);
//			interests.push(ShellFacade.FAVORITES_REMOVE);
//			interests.push(ShellFacade.PERSON_ADD_PREPARE);
//			interests.push(ShellFacade.TILE_PEOPLE_GET_PUBLIC_PHOTOS);
			return interests;
		}
		
		override public function handleNotification(note:INotification) : void {
			switch(note.getName()) {
				default:
					var msg:Message = new Message(note.getName(), null, note);
					junction.sendMessage(PipeAwareModule.MODULE_TO_APP_PIPE, msg);
					super.handleNotification(note);
			}
		}
		
		override public function handlePipeMessage(message:IPipeMessage) : void {
//			Handle our Application -> Module integration
			if(message.getBody() is INotification) {
				var note:INotification = message.getBody() as INotification;
				switch(note.getName()) {
//					case ShellFacade.TO_CLOSE_PHOTO_INFO_WINDOW:
					case ShellFacade.CHANGE_PHOTO_IN_PHOTO_INFO_WINDOW:
						sendNotification(note.getName(), note.getBody(), note.getType());
						break;
				}
			}
		}
	}
}